package com.example.countdownlatch;

import java.util.concurrent.CountDownLatch;

public class CountDownLatchMain {


    public static void main(String[] args) {
        CountDownLatch countDownLatch = new CountDownLatch(5);

        for (int i=0;i<15;i++){
            int finalI = i;
            new Thread(()->{
                try {
                    Thread.sleep(finalI *500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+"线程执行");
                countDownLatch.countDown();
            }).start();
        }

        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("执行完成");

    }

}
